<template>
	<view class="unitRegisterTwo">
		<f-navbar title="社会单位注册" :iconLeft="true" :isBack="true" @goBack="goBack" />
		{{unitSubmitInfo.phone}}
		<view class="unitRegisterTwo-header-state ff-align-items ff-text-center">
			<view class="unitRegisterTwo-header-state-box">
				<image class="ff-margin-bottom-6"
					src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/step-1.png" mode="">
				</image>
				<view class="ff-font-12">单位信息</view>
			</view>
			<view class="unitRegisterTwo-header-state-line"></view>
			<view class="unitRegisterTwo-header-state-box">
				<image class="ff-margin-bottom-6"
					src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/step-1.png" mode="">
				</image>
				<view class="ff-font-12">管理员信息</view>
			</view>
		</view>
		<view class="unitRegisterTwo-content">
			<view class="unitRegisterTwo-content-one ff-bg-fff ff-font-14 ff-margin-12 ff-border-radius-10">
				<view class="ff-font-weight-600 ff-font-17 ff-margin-bottom-5">管理员信息</view>
				<view class="ff-flex-between ff-border-bottom">
					<view class="unitRegisterTwo-content-one-title">管理员姓名</view>
					<input class="ff-text-right" type="text" @blur="changeNameFaceState"
						v-model.trim="unitSubmitInfo.username" placeholder="请输入" placeholder-style="color:#999" />
				</view>
				<view class="ff-flex-between ff-border-bottom">
					<view class="unitRegisterTwo-content-one-title">管理员手机号码</view>
					<input class="ff-text-right" type="number" maxlength="11" :disabled="true"
						v-model.trim="unitSubmitInfo.phone" placeholder="请输入" placeholder-style="color:#999" />
				</view>
				<view class="ff-flex-between ff-border-bottom">
					<view class="unitRegisterTwo-content-one-title">验证码</view>
					<view class="ff-align-items-one">
						<input type="number" v-model.trim="unitSubmitInfo.validCode" placeholder="请输入"
							placeholder-style="color:#999" />
						<view>
							<view @click="getVerifyPhone" v-if="validCodeList.disableValidCode"
								class="ff-color-confirm">{{ validCodeList.validCodeText }}</view>
							<view v-else class="ff-color-cancel">{{ validCodeList.validTimeText }}</view>
						</view>
					</view>
				</view>
				<view class="ff-flex-between ff-border-bottom">
					<view class="unitRegisterTwo-content-one-title">身份证号</view>
					<input style="width: 400rpx;" class="ff-text-right" type="idcard" maxlength="18"
						@blur="changeIdcardFaceState" v-model.trim="unitSubmitInfo.userIdCard" placeholder="请输入"
						placeholder-style="color:#999" />
				</view>
				<view class="ff-flex-between ff-border-bottom ff-align-items-one">
					<view class="unitRegisterTwo-content-one-title">身份信息认证</view>
					<view>
						<view v-if="!faceInfo.faceState" @click="faceRecognition"
							class="FaceBox ff-color-fff ff-font-12 ff-border-radius-5">人脸识别</view>
						<view v-else class="ff-color-confirm">人脸认证通过</view>
					</view>
				</view>
				<view class="ff-flex-between ff-border-bottom">
					<view class="unitRegisterTwo-content-one-title">设置密码</view>
					<input class="ff-text-right" type="password" v-model.trim="unitSubmitInfo.password"
						placeholder="请输入" placeholder-style="color:#999" />
				</view>
				<view class="ff-flex-between ff-border-bottom">
					<view class="unitRegisterTwo-content-one-title">再次输入密码</view>
					<input class="ff-text-right" type="password" v-model.trim="confirmPassword" placeholder="请输入"
						placeholder-style="color:#999" />
				</view>
			</view>
			<view class="unitRegisterTwo-content-but">
				<view class="unitRegisterTwo-content-but-box"><u-button type="primary" shape="circle"
						@click="submitClick">提交</u-button></view>
			</view>
		</view>
		<u-modal v-model="infoModal" :show-cancel-button="true" @confirm="confirmInfo" title="温馨提示"
			:content-style="{ 'line-height': '1.5' }" content="退出后, 您填写的内容将不会被保存" />
		<!-- 用户确认信息弹框 -->
		<u-modal title="温馨提示" v-model="userInfoModal" :show-cancel-button="true" @confirm="confirmUserInfo"
			:content-style="{ 'line-height': '1.5' }" content="请您确定身份证号码和姓名是您本人且正确无误，否则将不能完成身份认证！" />
		<!-- 用户验证弹框 -->
		<u-modal title="录制人脸视频警告" v-model="userWarningModal" @confirm="confirmUserWarning"
			:content="faceInfo.sessionCode" :content-style="{ 'line-height': '1.5' }" />
		<!-- 认证失败弹框 -->
		<u-modal :title="failTitle" v-model="failModal" :content-style="{ 'line-height': '1.5' }"
			:content="failContent" />
		<f-loading ref="loading" />
		<u-toast ref="uToast" />
		<!-- 多账号登录 -->
		<u-popup v-model="multiState" mode="bottom" :mask-close-able="false" :closeable="true" border-radius="40"
			:safe-area-inset-bottom="true">
			<view class="multi">
				<view class="multi-title ff-font-18 ff-font-weight-600 ff-text-center ff-margin-bottom-30">请选择本次登录的账号
				</view>
				<view class="multi-content ff-flex-between ff-bg-fff ff-border-radius-10 ff-margin-bottom-15"
					v-for="(item, index) of multiList" :key="index" @click="multiClick(item)">
					<view class="ff-align-items-one">
						<image src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/reg-3.png"
							mode="">
						</image>
						<view class="multi-content-info">
							<view class="ff-font-15 ff-margin-bottom-8 ff-line-height-1-3">{{ item.companyName }}</view>
							<view class="ff-font-13">{{ item.name }}</view>
						</view>
					</view>
					<view class="multi-content-select">
						<image v-show="item.id != loginSelectId"
							src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/no-select.png"
							mode="">
						</image>
						<image v-show="item.id == loginSelectId"
							src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/select.png"
							mode="">
						</image>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import config from '@/tools/config.js';
	export default {
		name: 'unitRegisterTwo',
		data() {
			return {
				infoModal: false, // 消息提示弹框的显/隐
				userInfoModal: false, // 确认管理员身份证号和姓名的弹框
				failTitle: '', // 失败弹框的标题
				failContent: '', // 失败弹框的提示语
				failModal: false, // 失败弹框的显/隐
				userWarningModal: false, // 用户录制视频警告弹框
				unitSubmitInfoLenghth: '', // 初始的社会单位信息字符串长度
				// 倒计时系列内容
				validCodeList: {
					validCodeText: '获取验证码', // 获取验证码
					validTimeText: '60秒', // 倒计时文案
					disableValidCode: true, // 按钮是否可以点击
					count: 60, // 倒计时秒数
					timer: null // 定时器
				},
				// 人脸识别相关
				faceInfo: {
					faceState: false, // 人脸识别（通过true，不通过false）
					sessionId: '', // 百度sessionId
					accessToken: '', // 百度accesstoken
					sessionCode: '', // 用户需要大声读出数字
					videoPath: '', // 上传视频后返回的临时视频路径
					videoBase64: '', // 视频base64
					imageBase64: '' // 图片base64
				},
				// 社会单位注册提交的信息
				confirmPassword: '', // 再次确认登录密码
				unitSubmitInfo: {
					regType: 1, // 注册类型(1:社会单位注册 2:服务机构注册 11:社会单位员工注册 21:服务机构员工注册 31:维保专家注册)
					company: {}, // 社会单位注册对象
					username: '', // 用户名称
					phone: '', // 手机号码(登录手机号码)
					validCode: '', // 手机验证码(注册手机验证码)
					departmentId: '', // 所属消防救援机构id
					userIdCard: '', // 用户身份证号码
					password: '' // 登录密码
				},
				multiState: false, // 多账号登录弹框
				loginSelectId: '', // 多账号登录选中/未选中ID
				multiList: [], // 多账号登录数据列表
			};
		},
		onLoad(e) {
			// console.log('前页面传过来的数据-----', e);
			let unitInfo = JSON.parse(e.unitInfo);
			this.unitSubmitInfo.departmentId = unitInfo.departmentId;
			delete unitInfo.departmentId;
			this.unitSubmitInfo.company = unitInfo;
			this.unitSubmitInfoLenghth = JSON.stringify(this.unitSubmitInfo).length; // 初始的社会单位信息数据长度
			this.unitSubmitInfo.phone = uni.getStorageSync('asdPhone') || '';
		},
		methods: {
			// 返回上一层页面
			goBack() {
				if (JSON.stringify(this.unitSubmitInfo).length != this.unitSubmitInfoLenghth) {
					this.infoModal = true;
				} else {
					this.$pageJump.navigateBack();
				}
			},
			// 返回上一层--确认按钮
			confirmInfo() {
				this.$pageJump.navigateBack();
			},
			// 点击获取短信验证码----验证手机号是否已注册
			getVerifyPhone() {
				if (this.$check.isMobile(this.unitSubmitInfo.phone)) {
					this.$refs.loading.openLoading('提交中···'); // 打开loading动画
					this.$http.get({
						url: `/sys/user/exist/${this.unitSubmitInfo.phone}`
					}).then(res => {
						// console.log('检验验证手机号是否已注册----', res);
						this.$refs.loading.closeLoading(); // 关闭loading动画
						if (res.code == 200 && res.data) {
							this.getValidCoded(); // 获取短信验证码
						} else {
							uni.showModal({
								title: '温馨提示',
								content: '该手机号已存在，无法注册。请使用新的手机号进行注册。',
								confirmColor: '#3178FF',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {}
								}
							})
						}
					});
				} else {
					this.$refs.uToast.show({
						title: '请输入正确管理员手机号码',
						type: 'error'
					});
				}
			},
			// 点击获取短信验证码----发送短信验证码
			getValidCoded() {
				this.$refs.loading.openLoading('提交中···'); // 打开loading动画
				this.$http.get({
					url: `/sys/user/sendRegCode/${this.unitSubmitInfo.phone}`
				}).then(res => {
					// console.log('获取短信验证码----', res);
					if (res.code == 200 && res.data) {
						this.$refs.loading.closeLoading(); // 关闭loading动画
						this.$refs.uToast.show({
							title: '验证码发送成功',
							type: 'success'
						});
						this.validCodeList.count = 60;
						this.validCodeList.disableValidCode = false;
						this.validCodeList.timer = setInterval(() => {
							if (this.validCodeList.count > 0 && this.validCodeList.count <= 60) {
								this.validCodeList.validTimeText = this.validCodeList.count + '秒';
								this.validCodeList.count--;
							} else {
								this.validCodeList.disableValidCode = true;
								this.validCodeList.validCodeText = '重新获取';
								this.validCodeList.validTimeText = '60秒';
								clearInterval(this.validCodeList.timer);
								this.validCodeList.timer = null;
							}
						}, 1000);
					} else {
						this.$refs.loading.closeLoading(); // 关闭loading动画
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error'
						});
					}
				});
			},

			// 人脸识别-----系列操作------------------------
			// 当姓名改变的时候，需要重新认证人脸
			changeNameFaceState() {
				this.faceInfo.faceState = false; // 人脸认证的状态
			},
			// 当身份证号改变的时候，需要重新认证人脸
			changeIdcardFaceState() {
				this.faceInfo.faceState = false; // 人脸认证的状态
			},
			// 人脸识别
			faceRecognition() {
				if (this.unitSubmitInfo.username == '') {
					this.$refs.uToast.show({
						title: '管理员姓名不能为空',
						type: 'error'
					});
					return;
				}
				if (!this.$check.IDCardCheck(this.unitSubmitInfo.userIdCard)) {
					this.$refs.uToast.show({
						title: '请正确输入管理员身份证号',
						type: 'error'
					});
					return;
				}
				this.userInfoModal = true; // 打开用户确认弹框并进行下一步操作
			},
			// 获取活体认证的数字验证码
			confirmUserInfo() {
				let that = this;
				that.$refs.loading.openLoading('开始人脸认证···'); // 打开loading动画
				that.$http.post({
					url: `/face/baidubce/faceliveness/sessioncode/${that.unitSubmitInfo.userIdCard}`
				}).then(res => {
					// console.log('获取活体认证的数字验证码---', res);
					if (res.code == 200 && res.data.code != '') {
						that.faceInfo.sessionId = res.data.sessionId;
						that.faceInfo.accessToken = res.data.accessToken;
						that.faceInfo.sessionCode = '人脸视频录制过程中，请大声的读出：' + res.data.code;
						that.userWarningModal = true; // 打开用户录制视频警告弹框
					} else {
						that.failTitle = '温馨提示'; // 失败的标题
						that.failContent = res.msg; // 失败的提示语
						that.failModal = true; // 失败弹框的显/隐
					}
					that.$refs.loading.closeLoading(); // 关闭loading动画
				});
			},
			// 警告用户录制视频
			confirmUserWarning() {
				let that = this;
				that.$refs.loading.openLoading(); // 打开loading动画
				uni.chooseVideo({
					count: 1,
					sourceType: ['camera'],
					camera: 'front',
					maxDuration: 5,
					compressed: true,
					success(res) {
						// console.log('返回视频文件的临时文件路径-----', res);
						that.faceInfo.videoPath = res.tempFilePath;
						// 获取全局唯一的文件管理器
						uni.getFileSystemManager().readFile({
							filePath: that.faceInfo.videoPath, //选择视频返回的相对路径
							encoding: 'base64', //编码格式
							success: res => {
								//成功的回调
								that.faceInfo.videoBase64 = res.data;
								// console.log('图片转成base64-------', that.faceInfo.videoBase64);
								that.startVideoFaceProcess(); // 进行活体检测
							},
							fail: res => {
								that.$refs.loading.closeLoading(); // 关闭loading动画
								that.failTitle = '温馨提示'; // 失败的标题
								that.failContent = '出现错误，请及时联系管理员！'; // 失败的提示语
								that.failModal = true; // 失败弹框的显/隐
							}
						});
					},
					fail() {
						that.$refs.loading.closeLoading(); // 关闭loading动画
						that.failTitle = '温馨提示'; // 失败的标题
						that.failContent = '出现错误，请检查是否打开相机等权限！'; // 失败的提示语
						that.failModal = true; // 失败弹框的显/隐
					}
				});
			},
			// 活体视频认证(后台的接口)
			startVideoFaceProcess() {
				let that = this;
				let verifyVideo = {
					sessionId: that.faceInfo.sessionId,
					accessToken: that.faceInfo.accessToken,
					videoBase64: that.faceInfo.videoBase64, // base64 编码的视频数据
					lipIdentify: 'COMMON', // 辅助语音验证进行，用于判断验证码是否为当事人读出取值, COMMON代表使用唇语识别，STRICT代表使用唇语识别并使用更加严格的策略判断是否通过， OFF代表关闭唇语识别，默认OFF
					idcard: that.unitSubmitInfo.userIdCard
				};
				// 请求视频认证检测（后台返回的视频数据）
				that.$refs.loading.openLoading('活体认证中，请稍候'); // 打开loading动画
				that.$http
					.post({
						url: '/face/baidubce/faceliveness/verify',
						data: verifyVideo
					})
					.then(res => {
						// console.log('获取活体认证检测返回得数据--------', res);
						// 活体认证结果 0：成功 1：失败
						if (res.code == 200 && res.data.errNo == 0) {
							that.faceInfo.imageBase64 = res.data.faceUrl; // 获取到后台返回的百度人脸图片地址
							that.faceInfo.accessToken = res.data.accessToken; // 更新百度accesstoken
							that.getBaiduTesting(); // 百度人脸库检测（检测是否是人脸）
						} else if (res.code == 200 && res.data.errNo == 1) {
							that.$refs.loading.closeLoading(); // 关闭loading动画
							that.failTitle = '温馨提示'; // 失败的标题
							that.failContent = res.data.errMsg; // 失败的提示语
							that.failModal = true; // 失败弹框的显/隐
						} else {
							that.$refs.loading.closeLoading(); // 关闭loading动画
							that.failTitle = '温馨提示'; // 失败的标题
							that.failContent = res.msg; // 失败的提示语
							that.failModal = true; // 失败弹框的显/隐
						}
					});
			},
			// 百度人脸库检测（检测是否是人脸）
			getBaiduTesting() {
				let that = this;
				that.$refs.loading.openLoading('人脸识别中，请稍候'); // 打开loading动画
				uni.request({
					url: 'https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=' + that.faceInfo
						.accessToken,
					method: 'POST',
					data: {
						image: that.faceInfo.imageBase64, // 图片信息(总数据大小应小于10M)，图片上传方式根据image_type来判断
						image_type: 'BASE64',
						face_fields: 'age,beauty,expression,face_shape,gender,glasses,landmark,landmark150,race,quality,eye_status,emotion,face_type',
						liveness_control: 'NORMAL' // 通过率
					},
					header: {
						'Content-Type': 'application/json'
					},
					success(res) {
						// console.log('人脸检测返回的数据-------', res);
						// Math.abs 函数返回指定数字 “x“ 的绝对值,列如 -1 ==> 1。
						if (
							res.data.error_msg == 'SUCCESS' &&
							res.data.result.face_num == 1 &&
							res.data.result.face_list[0].face_probability == 1 &&
							Math.abs(res.data.result.face_list[0].angle.pitch) < 20 &&
							Math.abs(res.data.result.face_list[0].angle.roll) < 20 &&
							Math.abs(res.data.result.face_list[0].angle.yaw) < 20 &&
							res.data.result.face_list[0].liveness.livemapscore > 0.393241
						) {
							that.getPublicTesting(); // 调取公安库检测的接口
						} else {
							that.$refs.loading.closeLoading(); // 关闭loading动画
							that.failTitle = '温馨提示'; // 失败的标题
							that.failContent = '视频不符合要求，请重拍！'; // 失败的提示语
							that.failModal = true; // 失败弹框的显/隐
						}
					}
				});
			},
			// 公安库检测
			getPublicTesting() {
				let that = this;
				let identityInfo = {
					name: that.unitSubmitInfo.username,
					idcard: that.unitSubmitInfo.userIdCard,
					image: 'data:image/png;base64,' + that.faceInfo.imageBase64
				};
				// 公安系统接口认证
				that.$refs.loading.openLoading('身份认证中，请稍候'); // 打开loading动画
				that.$http
					.post({
						url: '/face/idcard',
						data: JSON.stringify(identityInfo)
					})
					.then(res => {
						// console.log('公安系统接口认证------', res);
						if (res.code == 200 && res.data.isvalid) {
							that.addBaiduFaceLibrary(); // 公安库认证成功，上传图片到百度人脸库
						} else {
							that.$refs.loading.closeLoading(); // 关闭loading动画
							that.failTitle = '温馨提示'; // 失败的标题
							that.failContent = '公安系统身份认证失败，请重新认证!'; // 失败的提示语
							that.failModal = true; // 失败弹框的显/隐
						}
					});
			},
			// 上传人脸照片到人脸库
			addBaiduFaceLibrary() {
				// 新增人脸或者更新人脸到人脸库
				let that = this;
				that.$refs.loading.openLoading('人脸上传中，请稍候'); // 打开loading动画
				wx.request({
					url: 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add?access_token=' + that.faceInfo
						.accessToken,
					method: 'POST',
					data: {
						image: that.faceInfo.imageBase64,
						image_type: 'BASE64',
						group_id: config.baidu_group_id, //自己建的用户组id
						user_id: config.baidu_userid_pre + that.unitSubmitInfo.userIdCard //这里获取用户昵称
					},
					header: {
						'Content-Type': 'application/json'
					},
					success(res) {
						// console.log('新增百度人脸库返回的数据----', res);
						if (res.data.error_msg == 'SUCCESS') {
							that.$refs.loading.closeLoading(); // 关闭loading动画
							that.failTitle = '温馨提示';
							that.failContent = '认证成功!';
							that.failModal = true;
							that.faceInfo.faceState = true;
						} else if (res.data.error_code == '222210' || res.data.error_code == '223105') {
							// 222210：人脸库中用户下的人脸数目超过限制，223105：该人脸已存在
							that.upateBaiduFaceLibrary(); // 更新百度人脸库
						} else {
							that.$refs.loading.closeLoading(); // 关闭loading动画
							that.failTitle = '温馨提示'; // 失败的标题
							that.failContent = res.data.error_msg; // 失败的提示语
							that.failModal = true; // 失败弹框的显/隐
						}
					}
				});
			},
			// 更新百度人脸库
			upateBaiduFaceLibrary() {
				let that = this;
				that.$refs.loading.openLoading('人脸更新中，请稍候'); // 打开loading动画
				wx.request({
					url: 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/update?access_token=' + that
						.faceInfo.accessToken,
					method: 'POST',
					data: {
						image: that.faceInfo.imageBase64,
						image_type: 'BASE64',
						group_id: config.baidu_group_id, //自己建的用户组id
						user_id: config.baidu_userid_pre + that.unitSubmitInfo.userIdCard //这里获取用户昵称
					},
					header: {
						'Content-Type': 'application/json'
					},
					success(res) {
						// console.log('更新百度人脸库返回数据------', res);
						if (res.data.error_msg == 'SUCCESS') {
							that.failTitle = '温馨提示'; // 失败的标题
							that.failContent = '人脸更新成功！'; // 失败的提示语
							that.failModal = true; // 失败弹框的显/隐
							that.faceInfo.faceState = true;
						} else {
							that.failTitle = '温馨提示'; // 失败的标题
							that.failContent = res.data.error_msg; // 失败的提示语
							that.failModal = true; // 失败弹框的显/隐
						}
						that.$refs.loading.closeLoading(); // 关闭loading动画
					}
				});
			},
			// 点击注册操作
			submitClick() {
				if (this.unitSubmitInfo.username == '') {
					this.$refs.uToast.show({
						title: '请输入管理员姓名',
						type: 'error'
					});
					return;
				}
				if (this.unitSubmitInfo.validCode == '') {
					this.$refs.uToast.show({
						title: '请输入验证码',
						type: 'error'
					});
					return;
				}
				if (!this.$check.IDCardCheck(this.unitSubmitInfo.userIdCard)) {
					this.$refs.uToast.show({
						title: '请正确输入管理员身份证号',
						type: 'error'
					});
					return;
				}
				if (!this.faceInfo.faceState) {
					this.$refs.uToast.show({
						title: '请进行人脸识别',
						type: 'error'
					});
					return;
				}
				if (this.unitSubmitInfo.password == '') {
					this.$refs.uToast.show({
						title: '请输入密码',
						type: 'error'
					});
					return;
				}
				if (this.unitSubmitInfo.password != this.confirmPassword) {
					this.$refs.uToast.show({
						title: '两次密码不一致，请重新输入',
						type: 'error'
					});
					return;
				}
				this.$refs.loading.openLoading('注册中···'); // 打开loading动画
				this.$http
					.post({
						url: '/sys/user/regV3',
						data: this.unitSubmitInfo
					})
					.then(res => {
						// console.log('注册返回的结果-----', res);
						if (res.code == 200 && res.success) {
							this.$refs.loading.closeLoading(); // 关闭loading动画
							this.loginGo() // 去登录
						} else {
							this.$refs.loading.closeLoading(); // 关闭loading动画
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}
					});
			},
			// 去登录
			async loginGo() {
				const res = await this.$http.post({
					url: '/loginASD',
					data: {
						param: encrypt(this.staffRegister.phone)
					}
				})
				if (res.code == 200 && res.success && res.data.multipleUsers !== null) {
					this.multiAccountLogin(params) // 多账号登录
				} else if (res.code == 200 && res.success) {
					this.setUserInfo(res.data.user); // 登录后获取的用户信息
					this.loginHandle(res.data.user); // 去登录
				} else if (res.code == 5101) {
					uni.showModal({
						title: '温馨提示',
						content: res.msg,
						confirmColor: '#3178FF',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {}
						}
					})
				} else {
					this.$refs.uToast.show({
						title: res.msg,
						type: 'error'
					});
				}
				this.$refs.loading.closeLoading(); // 定义loadingTxt内容
			},
			// 多账号登录(账号密码)
			multiAccountLogin(e) {
				// console.log('多账号登录的信息列表--------', e);
				this.multiList = e.multipleUsers; // 账号列表赋值
				this.multiState = true; // 打开多账号登录弹框
			},
			// 多账号登录------选择某一个人员登录
			multiClick(item) {
				this.loginSelectId = item.id;
				this.$refs.loading.openLoading('登录中···');
				this.$http
					.post({
						url: '/multipleLoginASD',
						data: {
							param: encrypt(item.id)
						}
					})
					.then(res => {
						// console.log('多账号登录返回的数据---------', res);
						if (res.code == 200 && res.success) {
							this.setUserInfo(res.data.user); // 登录后获取的用户信息
							this.loginHandle(res.data.user); // 登录成功后判断人员类型
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}
						this.$refs.loading.closeLoading();
					});
			},
			// 登录后赋值操作
			loginHandle(uerInfo) {
				let userType = uerInfo.userType; // 1:监管人员  5:单位用户  8:维保人员  10:技术人员
				switch (userType) {
					case 1: // 监管人员
						// hasOwnProperty() 方法会返回一个布尔值，指示对象自身属性中是否具有指定的属性
						if (uerInfo.superviseStaff != null && uerInfo.hasOwnProperty('superviseStaff')) {
							// status：(0:未审核 1:已审核 5:已禁用)
							// staffType：(1:救援机构负责人, 2:救援机构专家 ,3:救援机构人员)
							let status = uerInfo.superviseStaff.status;
							let staffType = uerInfo.superviseStaff.staffType;
							if (status == 0) {
								//未审核
								uni.showModal({
									title: '温馨提示',
									content: '您的账号处于待审核状态，请联系您的单位确认审核后再登录！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 5) {
								//已禁用
								uni.showModal({
									title: '温馨提示',
									content: '您的账号已被禁用，请联系管理员！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 1) {
								uni.setStorageSync('isUserState', true); // 登录状态
								//已审核
								switch (staffType) {
									case 1: // 监管管理员
										this.setRoleStatus(4);
										break;
									case 2: // 监管员工
									case 3:
										this.setRoleStatus(5);
										break;
									default:
										break;
								}
								this.$pageJump.reLaunch('/pages/supervise/index'); // 跳转到监管页面
							} else {
								uni.showModal({
									title: '温馨提示',
									content: '您没有登录权限！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							}
						} else {
							uni.showModal({
								title: '温馨提示',
								content: '请求服务失败，请及时联系管理员！',
								confirmColor: '#3178FF',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {}
								}
							})
						}

						break;
					case 5: // 单位
						if (uerInfo.companyStaff != null && uerInfo.hasOwnProperty('companyStaff')) {
							let status = uerInfo.companyStaff.status;
							let staffType = uerInfo.companyStaff.staffType;
							if (status == 0) {
								//未审核
								uni.showModal({
									title: '温馨提示',
									content: '您的账号处于待审核状态，请联系您的单位确认审核后再登录！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 5) {
								// 已禁用
								uni.showModal({
									title: '温馨提示',
									content: '您的账号已被禁用，请联系管理员！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 1) {
								uni.setStorageSync('isUserState', true); // 登录状态
								// 已审核
								switch (staffType) {
									case 1: // 管理员
										this.setRoleStatus('0');
										break;
									case 5: // 员工
										this.setRoleStatus(1);
										break;
									default:
										break;
								}
								this.$pageJump.reLaunch('/pages/homeCentral/Central'); // 跳转到中心页面
							} else {
								uni.showModal({
									title: '温馨提示',
									content: '您没有登录权限！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							}
						} else {
							uni.showModal({
								title: '温馨提示',
								content: '请求服务失败，请及时联系管理员！',
								confirmColor: '#3178FF',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {}
								}
							})
						}
						break;
					case 8: // 维保人员
						if (uerInfo.orgStaff != null && uerInfo.hasOwnProperty('orgStaff')) {
							//机构员工
							let status = uerInfo.orgStaff.status;
							let staffType = uerInfo.orgStaff.staffType;
							if (status == 0) {
								//未审核
								uni.showModal({
									title: '温馨提示',
									content: '您的账号处于待审核状态，请联系您的机构确认审核后再登录！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
								return;
							} else if (status == 5) {
								//已禁用
								uni.showModal({
									title: '温馨提示',
									content: '您的账号已被禁用，请联系管理员！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 1) {
								uni.setStorageSync('isUserState', true); // 登录状态
								//已审核
								switch (staffType) {
									case 1: //管理员
										this.setRoleStatus(2);
										break;
									case 5: //员工
										this.setRoleStatus(3);
										break;
									default:
										break;
								}
								this.$pageJump.reLaunch('/pages/homeCentral/Central'); // 跳转到中心页面
							} else {
								uni.showModal({
									title: '温馨提示',
									content: '您没有登录权限！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							}
						} else {
							uni.showModal({
								title: '温馨提示',
								content: '请求服务失败，请及时联系管理员！',
								confirmColor: '#3178FF',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {}
								}
							})
						}
						break;
					case 10: //技术人员
						uni.showModal({
							title: '温馨提示',
							content: '技术人员服务暂未开放！',
							confirmColor: '#3178FF',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {}
							}
						})
						break;
					default:
						break;
				}
			},
		},
		onShareAppMessage() {
			return {
				title: '分享小程序给朋友',
				path: '/pages/homePage/Home'
			};
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #e6f2fe;
	}

	.unitRegisterTwo {
		&-header-state {
			background-color: #e6f2fe;
			position: fixed;
			top: 8.8%;
			left: 0;
			z-index: 11;
			width: 100%;
			justify-content: space-between;
			padding: 50rpx 5%;
			color: #6d7c99;

			&-box {
				image {
					width: 50rpx;
					height: 50rpx;
				}

				.step-number {
					width: 40rpx;
					height: 40rpx;
				}
			}

			&-line {
				width: 99rpx;
				height: 10rpx;
				background: #d2e5fa;
			}
		}

		&-content {
			margin-top: 220rpx;

			/deep/.u-icon {
				margin-left: 12rpx;
			}

			&-one {
				padding: 40rpx 26rpx 29rpx 26rpx;

				.ff-font-weight-600 {
					color: #0b204b;
				}

				.ff-border-bottom {
					padding: 40rpx 0;
					align-items: center;

					input {
						height: 28rpx;
						line-height: 1;
					}
				}

				&-title {
					color: #2a3c62;
				}

				.FaceBox {
					padding: 16rpx 19rpx;
					background-color: #0097ff;
					display: inline;
				}
			}

			&-but {
				padding: 120rpx 0 130rpx;
				margin: 0 6%;
				width: 88%;
				text-align: center;

				/deep/.u-size-default {
					height: 90rpx !important;
					line-height: 90rpx !important;
				}

				text {
					color: #3178ff;
				}
			}
		}
	}
</style>